package com.mapull.example.section1;

/**
 * StringSub 字符串截取
 *
 * @author mapull
 * @date 2021-09-06
 * @since 1.0
 **/
public class StringSub {

    public static void main(String[] args) {
        String text = "Hello world";
        CharSequence charSequence = text.subSequence(0, 5);
        System.out.println(charSequence);
    }

    public static void main5(String[] args) {
        String text = "Hello world";
        String substring = text.substring(5,8);
        System.out.println(substring);// wo
    }
    public static void main2(String[] args) {
        String text = "Hello world";
        String substring = text.substring(3,8);
        System.out.println(substring);//lo wo
    }

    public static void main1(String[] args) {
        String text = "Hello world";
        String substring = text.substring(3);
        System.out.println(substring); //lo world
        String substring2 = text.substring(text.length());
        System.out.println(substring2); // ''
        String substring3 = text.substring(0);
        System.out.println(substring3); //Hello world
        String substring4 = text.substring(100); //java.lang.StringIndexOutOfBoundsException: String index out of range: -89
    }
}
